package com.rec.smile.rpc.registry.redis;

import java.net.URI;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import com.rec.smile.rpc.api.util.Constant;
import com.rec.smile.rpc.registry.RootRegistryApi;

public class RedisRegister extends RootRegistryApi {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(RedisRegister.class);
	
	private JedisPool jedisPool;
	public RedisRegister(String redisServerAddressUri) {
		jedisPool = new JedisPool(URI.create(redisServerAddressUri));
	}

	@Override
	public void register(String serverAddress) {
		try (Jedis jedis = jedisPool.getResource()){
			jedis.publish(Constant.REDIS_DATA_PATH, serverAddress);
		} catch (Exception e) {
			LOGGER.error("register error", e);
		}
	}

}
